#ifndef _KON_EVENT_H_
#define _KON_EVENT_H_

#include <irrlicht.h>

using namespace irr;

class GameEventReceiver : public IEventReceiver {
    public:
        GameEventReceiver() {
            for (u32 i = 0; i < KEY_KEY_CODES_COUNT; ++i) {
                KeyIsDown[i] = false;
            }
            for (u32 i = 0; i < 3; ++i) {
                MouseDown[i] = false;
            }
        }
        
        virtual bool OnEvent(const SEvent &event) {
            if (event.EventType == EET_KEY_INPUT_EVENT) {
                KeyIsDown[event.KeyInput.Key] = event.KeyInput.PressedDown;
            }
            if (event.EventType == EET_MOUSE_INPUT_EVENT) {
                if (event.MouseInput.Event == EMIE_LMOUSE_PRESSED_DOWN) {
                    MouseDown[0] = true;
                }
                else if (event.MouseInput.Event == EMIE_LMOUSE_LEFT_UP) {
                    MouseDown[0] = false;
                }
            }
            return false;
        }
        
        virtual bool IsKeyDown(EKEY_CODE keyCode) const {
            return KeyIsDown[keyCode];
        }
        
        virtual bool IsMouseDown(u32 which) const {
            return MouseDown[which % 3];
        }
                
    private:
        bool KeyIsDown[KEY_KEY_CODES_COUNT];
        bool MouseDown[3];
};

#endif
 